package com.itheima.salarys.controller;

import com.itheima.common.controller.BaseController;
import com.itheima.common.entity.Result;
import com.itheima.common.entity.ResultCode;
import com.itheima.salarys.client.FeignClientService;
import com.itheima.salarys.pojo.ArchiveDetail;
import com.itheima.salarys.pojo.ArchiveMonthlyInfo;
import com.itheima.salarys.pojo.SalaryArchive;
import com.itheima.salarys.pojo.SalaryArchiveDetail;
import com.itheima.salarys.service.SalarysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;

/**
 * @author qiankaofei
 * @version 1.0
 * @date 2020/12/15 21:37
 */

@RestController
@RequestMapping("/salarys/user")
@CrossOrigin
public class SalaryArchiveController extends BaseController {

    @Autowired
    private SalarysService salarysService;

    /**
     * 查询工资归档
     */
    @GetMapping("/reports/{yearMonth}")
    public Result getArchiveSalaryReport(@PathVariable("yearMonth") String yearMonth
                                        ,@RequestParam("opType") Integer opType){
        List<SalaryArchiveDetail> salaryArchiveDetailList=new ArrayList<SalaryArchiveDetail>(0);
        if(opType==1){
            //未归档的
            salaryArchiveDetailList=salarysService.getReport(yearMonth,companyId);
        }else{
            //已归档的
            SalaryArchive salaryArchive=salarysService.findSalaryArchiveByYearMonthAndCompanyId(this.companyId,yearMonth);
            if(salaryArchive!=null){
                salaryArchiveDetailList=salarysService.findSalaryArchiveDetailListBySarlaryArciveId(salaryArchive.getId());
            }
        }
        return new Result(ResultCode.SUCCESS,salaryArchiveDetailList);
    }

    @Autowired
    private FeignClientService feignClientService;

    /**
     * fegin客户端测试1
     */
    @RequestMapping("/testfegin1")
    public Result getSocailDate(){
        ArchiveDetail socialInfo = feignClientService.getSocialInfo("1063705482939731968", "201906");
        return new Result(ResultCode.SUCCESS,socialInfo);
    }

    /**
     * fegin客户端测试2
     */
    @RequestMapping("/testfegin2")
    public Result getAttenDate(){
        ArchiveMonthlyInfo atteInfo = feignClientService.getAtteInfo("1063705482939731968", "201907");
        return new Result(ResultCode.SUCCESS,atteInfo);
    }
}
